package com.lxblyw.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.lxblyw.entity.ContactNote;
import com.lxblyw.util.DBHelp;
import com.lxblyw.util.RowMapper;

public class ContactNoteDao {
	DBHelp<ContactNote> db = new DBHelp<ContactNote>();

	public void save(ContactNote contactNote) {
		String sql = "Insert into t_contactnote(id,content,createtime,employeeid,contactid) values(?,?,?,?,?)";
		db.executeSQL(sql, contactNote.getId(),contactNote.getContent(),contactNote.getCreatetime(),contactNote.getEmployeeid(),contactNote.getContactid());
	}

	public List<ContactNote> findAllContent(String contactid) {
		String sql = "select id,content,createtime,employeeid,contactid from t_contactnote where contactid = ?";
		
		return db.executeQueryForList(sql, new ContactNoteRowMapper(), contactid);
	}

	private class ContactNoteRowMapper implements RowMapper<ContactNote> {

		public ContactNote mapperRow(ResultSet rs) throws SQLException {
			ContactNote contactNote = new ContactNote();
			contactNote.setId(rs.getString("id"));
			contactNote.setContent(rs.getString("content"));
			contactNote.setCreatetime(rs.getString("createtime"));
			contactNote.setEmployeeid(rs.getString("employeeid"));
			contactNote.setContactid(rs.getString("contactid"));
			return contactNote;
		}
		
	}

	public void delContactNote(String contactid) {
		String sql = "delete from t_contactnote where contactid=?";
		db.executeSQL(sql, contactid);
	}
}
